{extend name="public/base"}

{block name="x-body"}
<style>
    .layui-form-item .layui-form-label {
        width: 160px;
    }

    .layui-form-item .layui-input-inline {
        width: 400px;
    }

    #test9, #test11 {
        display: none;
    }

    #demo1, #demo2{
        width: 200px;
    }
</style>
    <div class="x-body">
        <form class="layui-form">
            {if $id}
            <input type="hidden" name="id" value="{$id}">
            {/if}

            <div class="layui-form-item">
                <label for="shipping_name" class="layui-form-label">
                    <span class="x-red">*</span>物流公司名字
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="shipping_name" name="shipping_name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$result.shipping_name}">
                </div>

            </div>

            <div class="layui-form-item">
                <label for="shipping_code" class="layui-form-label">
                    <span class="x-red">*</span>快递公司编码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="shipping_code" name="shipping_code" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$result.shipping_code}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="__STATIC__/common/excel/快递公司编码.xlsx" target="_blank" style="color: red;">查看快递编码</a>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label for="shipping_desc" class="layui-form-label">
                    简短描述
                </label>
                <div class="layui-input-inline">
                    <textarea placeholder="请输入内容" id="shipping_desc" name="shipping_desc" class="layui-textarea">{$result.shipping_desc}</textarea>
                </div>
            </div>

            <div class="layui-upload layui-form-item">
                <label class="layui-form-label">
                    物流图片图标
                </label>
                <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                <button type="button" class="layui-btn" id="test9">开始上传</button>
                <input type="hidden" name="shipping_logo" value="{$result.shipping_logo}" id="ad_img">

                <div class="layui-upload-list" style="display: {if !$result.template_img}none{/if};">
                    <label class="layui-form-label"></label>
                    <img class="layui-upload-img" id="demo1" src="{if $result}{:config('imgRoute')}{$result.shipping_logo}{/if}">
                    <p id="demoText"></p>
                </div>
            </div>

            <div class="layui-upload layui-form-item">
                <label class="layui-form-label">
                    模板图片
                </label>
                <button type="button" class="layui-btn layui-btn-normal" id="test10">选择文件</button>
                <button type="button" class="layui-btn" id="test11">开始上传</button>
                <input type="hidden" name="template_img" value="{$result.template_img}" id="ed_img">

                <div class="layui-upload-list" style="display: {if !$result.template_img}none{/if};">
                    <label class="layui-form-label"></label>
                    <img class="layui-upload-img" id="demo2" src="{if $result}{:config('imgRoute')}{$result.template_img}{/if}">
                    <p id="demoText2"></p>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="template_width" class="layui-form-label">
                    模板宽度
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="template_width" name="template_width"
                           autocomplete="off" class="layui-input" value="{$result.template_width}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    运单宽度，单位为毫米(mm)
                </div>
            </div>

            <div class="layui-form-item">
                <label for="template_height" class="layui-form-label">
                    模板高度
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="template_height" name="template_height"
                           autocomplete="off" class="layui-input" value="{$result.template_height}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    运单高度度，单位为毫米(mm)
                </div>
            </div>

            <div class="layui-form-item">
                <label for="template_offset_x" class="layui-form-label">
                    偏移量X
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="template_offset_x" name="template_offset_x"
                           autocomplete="off" class="layui-input" value="{$result.template_offset_x}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    运单模板左偏移量，单位为毫米(mm)
                </div>
            </div>

            <div class="layui-form-item">
                <label for="template_offset_y" class="layui-form-label">
                    偏移量Y
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="template_offset_y" name="template_offset_y"
                           autocomplete="off" class="layui-input" value="{$result.template_offset_y}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    运单模板上偏移量，单位为毫米(mm)
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="edit" lay-submit="" id="L_repass">
                    {$id ? '修改' : '增加'}
                </button>
            </div>
        </form>
    </div>
    <script>
        formData('{:url("MallConfig/shipping_form")}', 'edit', function (){
            window.parent.location.reload();

            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
        }, false);

        $(function (){
            layui.use(['form', 'upload'], function (){
                var upload = layui.upload;

                let url = '{:url("shipping_upload")}';

                uploadImg(upload, url);

                upload.render({
                    elem: '#test10'
                    ,url: url
                    ,choose: function (obj) {
                        //预读本地文件示例，不支持ie8
                        obj.preview(function (index, file, result) {
                            $('#demo2').attr('src', result); //图片链接（base64）
                        });
                        $("#test11").css('display', 'inline-block');
                        $(".layui-upload-list").css('display', 'block');
                    }
                    ,auto: false
                    ,accept: 'images'
                    ,field: 'img'
                    ,size: 2000
                    //,multiple: true
                    ,bindAction: '#test11'
                    ,done: function(res){
                        if(res.code == 1){
                            dialog(res.msg, false, 0);
                            $("#test11").css('display', 'none');
                            $("#ed_img").val(res.data.img);
                        }else{
                            dialog(res.msg, false, 0, function (){
                                $("#test11").html('重新上传');
                            });
                        }
                    }
                    , error: function () {
                        //演示失败状态，并实现重传
                        dialog('网络似乎开了一下小差……', false, 0);
                        $("#test9").html('重新上传');
                    }
                });
            });
        })
    </script>
{/block}